package com.valveinspectionsys.checkwork.db;

import java.util.ArrayList;
import java.util.List;

import com.valveinspectionsys.base.BaseDao;
import com.valveinspectionsys.dbhelp.DbTableName;
import com.valveinspectionsys.povo.CompetencePOVO;
import com.valveinspectionsys.util.FileNameUtil;
import com.valveinspectionsys.util.SharedPreferenceUtil;

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;



public class LoginDao extends BaseDao {
    
    private SQLiteDatabase db;
    
    private CompetencePOVO comp;
    
    private SharedPreferenceUtil sh;

    public LoginDao(Context context, String SqliteName) {
	super(context, SqliteName);
	this.db=super.getDb();
	this.comp=super.getComp();
	sh=new SharedPreferenceUtil(context);
    }
    
    /**
     * 当表册被重复
     * @param waterlistid
     * @return
     */
    public boolean delectRewater(String waterlistnumber){
         
	boolean b=false;
	  db.delete(DbTableName.RESOURCES, "waterlistid=?",new String[]{waterlistnumber});
        
          //删除导航数据
          db.delete(DbTableName.NAVIGATION, "waterlistid='"+waterlistnumber+"'", null);
          //删除水表数据
          db.delete(DbTableName.DEVICEINFO,"waterlistid='"+waterlistnumber+"'" , null);
        
                       
          db.delete(DbTableName.DEVICELIST, "waterlistid=?", new String[]{waterlistnumber});
         FileNameUtil fs=new FileNameUtil();
         fs.delectFile(comp.getUserID()+"/"+waterlistnumber);
	return b;
    }
    
    /**
     * 查询当前所有的表册编号
     * @return
     */
    public List<String> queryAllWaterlistId(){
	List<String> list=new ArrayList<String>();
	String sql="select * from waterlist";
	Cursor cursor=db.rawQuery(sql, null);
	while(cursor.moveToNext()){
	    
	    list.add(cursor.getString(cursor.getColumnIndex("waterlistid")));
	   
	}
	if(cursor!=null){
	    cursor.close();
	}
	return list;
    }

}
